<?php

declare(strict_types=1);

namespace App\Admin\Controller;

use App\Admin\Annotation\Auth;
use App\Admin\Service\System\SystemDeptService;
use App\Admin\Service\System\SystemPostService;
use App\Admin\Service\System\SystemRoleService;
use App\Admin\Service\System\SystemUserService;
use DI\Attribute\Inject;
use Newbie\Annotation\Attributes\Route\Controller;
use Newbie\Annotation\Attributes\Route\GetMapping;
use support\Request;
use support\Response;

/**
 * 公共方法控制器
 * Class CommonController
 * @package App\system\Controller
 */
#[Controller(prefix: "system/common"), Auth]
class CommonController extends BaseController {
    #[Inject]
    protected SystemUserService $userService;

    #[Inject]
    protected SystemDeptService $deptService;

    #[Inject]
    protected SystemRoleService $roleService;

    #[Inject]
    protected SystemPostService $postService;

    /**
     * 获取用户列表
     * @param Request $request
     * @return Response
     */
    #[GetMapping("getUserList")]
    public function getUserList (Request $request): Response {
        return $this->success($this->userService->getPageList($request->all()));
    }

    /**
     * 获取部门树列表
     * @return Response
     */
    #[GetMapping("getDeptTreeList")]
    public function getDeptTreeList (): Response {
        return $this->success($this->deptService->getSelectTree());
    }

    /**
     * 获取角色列表
     * @return Response
     */
    #[GetMapping("getRoleList")]
    public function getRoleList (): Response {
        return $this->success($this->roleService->getList());
    }

    /**
     * 获取岗位列表
     * @return Response
     */
    #[GetMapping("getPostList")]
    public function getPostList (): Response {
        return $this->success($this->postService->getList());
    }
}